var userinfo = {};
var loaddate = {};
var weibo = {};
$(document).ready(function(){
	
	checkLogin();
	initEvent();
	
	
});
/**
 * 检测是否已经登录
 * 基于Cookie
 */
function checkLogin(){
	var login = $.cookie('temp_login_username');
	
	if(login == undefined || login == null){
		//没有cookie的情况
	}else{
		
		new ConsoleItem({
			text:'登陆成功!',
			delay:2000,
			color:'#008000',
			id:'loginsuccess'
			
		});
		
		$('#login_div').fadeOut(100,function(){
			$('#content_div').fadeIn(300,function(){
				initContentDIV();
			});
		});
		
	}
	
	
}
/**
 * 初始化事件响应
 */
function initEvent(){
	
	$('.login_form_loginbutton').click(function(){
	
		validationLogin();
		
		
		
	});
	
	$('.login_form_resetbutton').click(function(){
		
		resetInput();
	});
	$(window).keydown(function(e){
		if(e.keyCode == 13 && $.cookie('temp_login_username') == undefined){
			$('.login_form_loginbutton').click();
		}
	});
	
	
	$('.GetDateListAction').click(function(){
		var wait = new weibo.WaitAlert();
		wait.show();
		new Ajax({
			ActionCode:20002,
			prm:{
				index:0,
				count:8
			},
			Success:function(data){
				console.debug(data);
				wait.close();
			},
			Error: function(){
				wait.close();
			}
			
		}).send();
		
	});
	
	$('.logout').click(function(){
		
		new ConsoleItem({
			text:'退出登陆!',
			delay:2000,
			color:'#ff0000',
			id:'logoutsuccess'
			
		});
		
		$('#content_div').fadeOut(100,function(){
			$('#login_div').fadeIn(300,function(){
				
				$.cookie('temp_login_username',null);
				$.cookie('temp_login_uid',null);
				$.cookie('temp_login_name',null);
				$('.user_info_content').text('');
				$('.task_div_content_button').remove();
				$('.task_div_content').html('欢迎登陆Temp Task！请查看日期列表中是否还有未填写的内容！');
			});
			
		});
		
	});
	
	$('.addDate').click(function(){
		
		var content = $('<div></div>').css('width','100%').css('height','100%');
		
		var datevaluehtml = $('<label title="日期">日期<input type="text" class="datevalue_input" style="margin:0 0 0 20px;" /></label>').css('margin','15px 0 20px 30px').css('float','left').css('width','100%');
		var descriptionhtml = $('<label title="周几">周几<input type="text" class="description_input" style="margin:0 0 0 20px;" /></label>').css('margin-left','30px').css('float','left').css('width','100%');
		var button = $('<div class="temp_button">发布</div>').css('margin','10px').css('float','left').css('width','60px').css('height','30px').css('line-height','30px');
		var canclebutton = $('<div class="temp_button">取消</div>').css('margin','10px').css('float','left').css('width','60px').css('height','30px').css('line-height','30px');
		var todaybutton = $('<div class="temp_button">今天</div>').css('margin','10px').css('float','left').css('width','60px').css('height','30px').css('line-height','30px');
		
		content.append(datevaluehtml).append(descriptionhtml).append(button).append(todaybutton).append(canclebutton);
		
		var adddate = new Dialog({
			width:350,
			height:200,
			content:content
		});
		adddate.show();
		canclebutton.click(function(){
			adddate.close();
		});
		todaybutton.click(function(){
			var now=new Date(); 
			var day=now.getDay();  
			var week;
			var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
			week=arr_week[day];
			var waitconsole = new ConsoleItem({
				text:'正在获取发布会议...',
				delay:0,
				color:'#000000',
				id:'senddate'
			});
		//	alert(week+' ,'+getNowFormatDate());
			
			new Ajax({
				ActionCode:20006,
				prm:{
					datevalue: getNowFormatDate(),
					description: week
				},
				Success:function(data){
					console.debug(data);
					if(data.res){
						adddate.close();
					}
					waitconsole.Close();
					new ConsoleItem({
						text:'发布会议成功！',
						delay:2000,
						color:'#008000',
						id:'senddatesuccess'
					});
					initContentDIV();
				}
			}).send();
		});
		button.click(function(){
			
			var dvalue = $(this).parent().find('.datevalue_input').val();
			var descvalue = $(this).parent().find('.description_input').val();
			
			if(dvalue == undefined || dvalue == '' || descvalue == undefined || descvalue == ''){
				alert('日期和周几不能为空！');
				return;
			}
			var waitconsole = new ConsoleItem({
				text:'正在获取发布会议...',
				delay:0,
				color:'#000000',
				id:'senddate'
			});
			new Ajax({
				ActionCode:20006,
				prm:{
					datevalue:dvalue,
					description:descvalue
				},
				Success:function(data){
					console.debug(data);
					if(data.res){
						adddate.close();
					}
					waitconsole.Close();
					new ConsoleItem({
						text:'发布会议成功！',
						delay:2000,
						color:'#008000',
						id:'senddatesuccess'
					});
					initContentDIV();
				}
			}).send();
			
	
			
		});
		
	});
	
	$('.addUser').click(function(){
		
		var content = $('<div></div>').css('width','100%').css('height','100%');
		
		var usernamehtml = $('<label title="账号">账号<input type="text" class="username_input" style="margin:0 0 0 20px;" /></label>').css('margin','15px 0 20px 30px').css('float','left').css('width','100%');
		var passwordhtml = $('<label title="密码">密码<input type="text" class="password_input" style="margin:0 0 0 20px;" /></label>').css('margin','0 0 20px 30px').css('float','left').css('width','100%');
		var namehtml = $('<label title="姓名">姓名<input type="text" class="name_input" style="margin:0 0 0 20px;" /></label>').css('margin-left','30px').css('float','left').css('width','100%');
		
		
		var button = $('<div class="temp_button">发布</div>').css('margin','40px 0 0 20px').css('float','left').css('width','60px').css('height','30px').css('line-height','30px');
		var canclebutton = $('<div class="temp_button">取消</div>').css('margin','40px 0 0 100px').css('float','left').css('width','60px').css('height','30px').css('line-height','30px');
		
		content.append(usernamehtml).append(passwordhtml).append(namehtml).append(button).append(canclebutton);
		
		var adduser = new Dialog({
			width:300,
			height:250,
			content:content
		});
		adduser.show();
		canclebutton.click(function(){
			adduser.close();
		});
		
		button.click(function(){
			
			var uvalue = $(this).parent().find('.username_input').val();
			var pvalue = $(this).parent().find('.password_input').val();
			var nvalue = $(this).parent().find('.name_input').val();
			
			if(uvalue == undefined || uvalue == '' || pvalue == undefined || pvalue == '' || nvalue == undefined || nvalue == ''){
				alert('账号、密码、姓名都不能为空！');
				return;
			}
			
			new Ajax({
				ActionCode:20007,
				prm:{
					username:uvalue,
					password:pvalue,
					name:nvalue
				},
				Success:function(data){
					console.debug(data);
					if(data.res){
						adduser.close();
					}
				}
			}).send();
		
		});
	});
	
	
	
	
	
	$('.viewAction').click(function(){
		
		$('#list_div').hide();
		$('#action_div').show();
		
		
		
	});
	
	$('.viewMeeting').click(function(){
		
		$('#action_div').hide();
		$('#list_div').show();
		
		
		
		
	});
	
	
	
	
	
}
function getNowFormatDate()
{
   var day = new Date();
   var Year = 0;
   var Month = 0;
   var Day = 0;
var CurrentDate = "";
   //初始化时间
   //Year       = day.getYear();//有火狐下2008年显示108的bug
   Year       = day.getFullYear();//ie火狐下都可以
   Month      = day.getMonth()+1;
   Day        = day.getDate();
   
   CurrentDate += Year + "-";
   
   if (Month >= 10 )
   {
    CurrentDate += Month + "-";
   }
   else
   {
    CurrentDate += "0" + Month + "-";
   }
   if (Day >= 10 )
   {
    CurrentDate += Day ;
   }
   else
   {
    CurrentDate += "0" + Day ;
   }
   return CurrentDate;
}
/**
 * 初始化ActionLIST
 */
function initActionList(){
	

	
	
	new Ajax({
		ActionCode:20010,
		Success:function(data){
			console.debug(data);
			$('#action_div').find('.datelist_item').remove();
			if(data.res){
			
				var actionContent = $('#action_div');
				
				var additem = $('<div class="datelist_item"></div>').css('text-align','center').text('增加Action').appendTo(actionContent);
				
				additem.click(function(){
					
					initActionContent({
						aid:-1,
						actionName:'',
						actionCode:'',
						actionDesc:'',
						actionRequest:'',
						actionSuccessPayload:'',
						actionErrorPayload:''
					});
					
					
					
				});
				
				for(var i = 0 ; i < data.pld.actions.length ; i ++){
					var actionItem = data.pld.actions[i];
					var datelist_item = $('<div class="datelist_item"></div>').attr('id',actionItem.aid).attr('actionCode',actionItem.actionCode).text(actionItem.actionName+" cod:"+actionItem.actionCode).appendTo(actionContent);
					
					
					datelist_item.data('actionItem',actionItem);
					datelist_item.css('padding-left','10px');
					
					datelist_item.click(function(){
						
						initActionContent($(this).data('actionItem'));
						
					});
					
					
				}
				
				
				
				
				
				
				
			}
			
			
			
			
		}
		
		
	}).send();
	
	
	
	
	
	
	
	
}
/**
 * 初始化Action内容
 */
function initActionContent(data){	
	
	new ConsoleItem({
		text:'正在加载Action内容',
		delay:1000,
		color:'#000000',
		id:'loadactioncontent'
	})
	
	
	var content = $('.task_div_content');
	content.html('');
	$('.task_div_content_button').remove();
	
	var nameDiv = $('<div class="task_name_div"></div>').css('background-image','red').css('height','auto').css('width','100%').css('float','left');
	var codeDiv = $('<div class="task_code_div"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
	var descDiv = $('<div class="task_desc_div"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
	var requestDiv = $('<div class="task_request_div"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
	var successDiv = $('<div class="task_success_div"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
	var errorDiv = $('<div class="task_error_div"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
	
	
	
	var nameLabel = $('<div class="task_name_label"></div>').text('ActionName(名称 name)').css('font-size','20px').css('width','100%').css('float','left');
	var codeLabel = $('<div class="task_code_label"></div>').text('ActionCode(编号 cod)').css('font-size','20px').css('width','100%').css('float','left');
	var descLabel = $('<div class="task_desc_label"></div>').text('ActionDesc(描述 desc)').css('font-size','20px').css('width','100%').css('float','left');
	var requestLabel = $('<div class="task_request_label"></div>').text('ActionRequest(请求 request)').css('font-size','20px').css('width','100%').css('float','left');
	var successLabel = $('<div class="task_success_label"></div>').text('ActionSuccessPayload(成功响应 Payload)').css('font-size','20px').css('width','100%').css('float','left');
	var errorLabel = $('<div class="task_error_label"></div>').text('ActionError(失败响应 Payload)').css('font-size','20px').css('width','100%').css('float','left');
	
	
	var nameText = $('<input type="text" class="task_name_text" />').css('padding','5px').css('width','200px').css('float','left').val(data.actionName);
	var codeText = $('<input type="text" class="task_code_text" />').css('padding','5px').css('float','left').val(data.actionCode);
	var descText = $('<textarea class="task_desc_text" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.actionDesc);
	var requestText = $('<textarea class="task_request_text" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.actionRequest);
	var successText = $('<textarea class="task_success_text" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.actionSuccessPayload);
	var errorText = $('<textarea class="task_error_text" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.actionErrorPayload);
	
	
	var buttondiv = $('<div class="task_div_content_button"></div>').css('background-image','blue').css('height','auto').css('top','20%').css('left','88%').css('position','absolute').css('width','80px').css('float','left').css('margin-top','20px');
	
	var button = $('<div class="temp_button">保存修改</div>').attr('aid',data.aid).css('float','left').css('height','40px').css('line-height','40px').css('width','80px');
	var dateview = $('<div></div>').text(data.actionName + " cod:"+data.actionCode).css('float','left').css('color','blue');
	
	button.data('actionItem',data);
	
	nameDiv.append(nameLabel).append(nameText);;
	codeDiv.append(codeLabel).append(codeText);;
	descDiv.append(descLabel).append(descText);;
	requestDiv.append(requestLabel).append(requestText);;
	successDiv.append(successLabel).append(successText);;
	errorDiv.append(errorLabel).append(errorText);;
	

	buttondiv.append(button).append(dateview);;
	$('body').append(buttondiv);
	content.append(nameDiv).append(codeDiv).append(descDiv).append(requestDiv).append(successDiv).append(errorDiv);
	
	button.click(function(){
		
		var dataItem = $(this).data('actionItem');
		
		var aid = dataItem.aid;
		var actionName = $('.task_name_text').val();
		var actionCode = $('.task_code_text').val();
		var actionDesc = $('.task_desc_text').val();
		var actionRequest = $('.task_request_text').val();
		var actionSuccess = $('.task_success_text').val();
		var actionError = $('.task_error_text').val();
		
		new Ajax({
			ActionCode:20008,
			prm:{
				aid:aid,
				actionName:actionName,
				actionDesc:actionDesc,
				actionCode:actionCode,
				actionRequest:actionRequest,
				actionSuccessPayload:actionSuccess,
				actionErrorPayload:actionError
			},
			Success:function(data){
				
				console.debug(data);
				new ConsoleItem({
					text:'保存action成功！',
					delay:2000,
					color:'#008000',
					id:'addactionsuccess'
				})
			}
			
			
			
		}).send();
		
		
//		var id = $(this).attr('mid');
//		var todaycontent = $('.text_today').val();
//		var comcontent = $('.text_com').val();
//		var questioncontent = $('.text_question').val();
//		
//		var savetemp = new ConsoleItem({
//			text:'正在保存会议记录...',
//			delay:0,
//			id:'savetemp'
//		});
//		
//		
//		new Ajax({
//			ActionCode:20003,
//			prm:{
//				today:todaycontent,
//				com:comcontent,
//				question:questioncontent,
//				mid:id
//			},
//			Success:function(data){
//				savetemp.fadeClose();
//				updateDateList(id, data);
//			}
//		}).send();
		
	});
	
	
	
	
}

/**
 * 验证登陆
 */
function validationLogin(){
	if($('#validationwait').size() > 0){
		return;
	}
	
	
	var username = $('.login_form_username_input').val();
	var password = $('.login_form_password_input').val();
	
	if(username == undefined || username == ''){
		new ConsoleItem({
			text:'用户名不能为空！',
			delay:2500,
			color:'#ff0000',
			id:'usernamevalidation'
		});
		return;
	}
	if(password == undefined || password == ''){
		new ConsoleItem({
			text:'密码不能为空！',
			delay:2500,
			color:'#ff0000',
			id:'passwordvalidation'
		});
		return;
	}
	
	var waitconsole = new ConsoleItem({
		text:'正在验证登陆信息...',
		delay:0,
		color:'#000000',
		id:'validationwait'
	});
	
	new Ajax({
		ActionCode:20001,
		prm:{
			username:username,
			password:password
		},
		Error:function(error){
			console.debug(error);
			waitconsole.fadeClose();
		},
		Success:function(data){
			console.debug(data);
			
			if(!data.res){
				waitconsole.Close();
				new ConsoleItem({
					text:data.pld.mri,
					delay:3000,
					color:'#ff0000',
					id:'validationloginerr'
				});
			}else{
				waitconsole.Close();
				new ConsoleItem({
					text:'登陆成功!',
					delay:3000,
					color:'#008000',
					id:'loginsuccess'
				});
				$.cookie('temp_login_username',username);
				$.cookie('temp_login_uid',data.pld.uid);
				$.cookie('temp_login_name',data.pld.name);
				$('#login_div').fadeOut(500,function(){
					$('#content_div').fadeIn(300,function(){
						initContentDIV();
					});
				});
			}
			
		}
		
	}).send();
	
	
	
	
}
/**
 * 初始化内容区域
 */
function initContentDIV(){
	
	initUserInfo();
	initDateList();
	initActionList();
}
/**
 * 初始化用户信息
 */
function initUserInfo(){
	userinfo.uid = $.cookie('temp_login_uid');
	userinfo.name = $.cookie('temp_login_name');
	userinfo.username = $.cookie('temp_login_username');
	$('.user_info_content').text('欢迎回来，'+userinfo.username+'('+userinfo.name+')');
	
	
	

}
/**
 * 初始化日期列表
 */
function initDateList(){
	
	loaddate.index = 0;
	loaddate.count = 100;
	loaddate.uid = userinfo.uid;
	
	$('#list_div').css('height',$(window).height() - 170);
	$('#action_div').css('height',$(window).height() - 170);
	$('#task_div').css('height',$('#list_div').height());
	var waitconsole = new ConsoleItem({
		text:'正在获取日期列表...',
		delay:0,
		color:'#000000',
		id:'getdatelist'
	});
	$('.user_select').remove();
	$('#list_div').find('.datelist_item').remove();
	
	if(userinfo.username == 'admin'){
		$('.addDate').show();
		$('.addUser').show();
		new Ajax({
			ActionCode:20005,
			Success:function(data){
				console.debug(data);
				
				var userselect = $('<select class="user_select"></select>').css('margin-bottom','10px').css('float','left').css('width','100%');
				
				for(var i = 0 ; i < data.pld.users.length ; i ++){
					var user = data.pld.users[i];
					if(user.username == 'admin'){
						continue;
					}
					var option = $('<option></option>').val(user.uid).text(user.username+'('+user.name+')');
					userselect.append(option);
				}
				
				$('#list_div').prepend(userselect);
				
				userselect.change(function(){
					
					loaddate.uid = $(this).val();
					
					$('#list_div').find('.datelist_item').remove();
					
					new Ajax({
						ActionCode:20002,
						prm:loaddate,
						Success:function(data){
							waitconsole.Close();
							if(data.res){
								new ConsoleItem({
									text:'日期列表加载成功！',
									delay:2000,
									color:'#000000',
									id:'getdatelistsuccess'
								});
								
								var list_div = $('#list_div');
								
								
								
								for(var i = 0 ; i < data.pld.date.length ; i ++){
									var dateitem = data.pld.date[i];
									var datelist_item = $('<div class="datelist_item"></div>').attr('id',dateitem.did).attr('dateview',dateitem.datevalue+" "+dateitem.description).text(dateitem.datevalue+" "+dateitem.description).appendTo(list_div);
									
									if(dateitem.question){
										var q = $('<span class="q_span" >?</span>').css('font-size','20px').css('color','red').css('float','left');
										datelist_item.prepend(q);
									}else{
										datelist_item.css('padding-left','10px');
									}
									
									
									datelist_item.css('font-size','14px');
									datelist_item.attr('mid',dateitem.mid);
									var today = $('<span class="today_span">今日计划</span>').css('font-size','12px').css('margin-left','10px');
									var com = $('<span class="com_span">完成情况</span>').css('font-size','12px').css('margin-left','5px');
									
									if(dateitem.today){
										today.css('color','green');
									}else{
										today.css('color','red');
									}
									
									if(dateitem.com){
										com.css('color','green');
									}else{
										com.css('color','red');
									}
									
									datelist_item.append(today).append(com);
									datelist_item.click(function(){
										initTaskContent($(this).attr('mid'));
									});
								}

								
							}else{
								new ConsoleItem({
									text:'日期列表加载失败！'+data.pld.mri,
									delay:3000,
									color:'#000000',
									id:'getdatelistfaild'
								});
							}
						}
						
					}).send();
					
				});
				userselect.change();
			}
		}).send();
		
		
		
		
		
	}else{
		$('.addDate').hide();
		$('.addUser').hide();
		new Ajax({
			ActionCode:20002,
			prm:loaddate,
			Success:function(data){
				waitconsole.Close();
				if(data.res){
					new ConsoleItem({
						text:'日期列表加载成功！',
						delay:2000,
						color:'#000000',
						id:'getdatelistsuccess'
					});
					
					var list_div = $('#list_div');
					
					
					
					for(var i = 0 ; i < data.pld.date.length ; i ++){
						var dateitem = data.pld.date[i];
						var datelist_item = $('<div class="datelist_item"></div>').attr('id',dateitem.did).attr('dateview',dateitem.datevalue+" "+dateitem.description).text(dateitem.datevalue+" "+dateitem.description).appendTo(list_div);
						
						if(dateitem.question){
							var q = $('<span class="q_span" >?</span>').css('font-size','20px').css('color','red').css('float','left');
							datelist_item.prepend(q);
						}else{
							datelist_item.css('padding-left','10px');
						}
						
						
						datelist_item.css('font-size','14px');
						datelist_item.attr('mid',dateitem.mid);
						var today = $('<span class="today_span">今日计划</span>').css('font-size','12px').css('margin-left','10px');
						var com = $('<span class="com_span">完成情况</span>').css('font-size','12px').css('margin-left','5px');
						
						if(dateitem.today){
							today.css('color','green');
						}else{
							today.css('color','red');
						}
						
						if(dateitem.com){
							com.css('color','green');
						}else{
							com.css('color','red');
						}
						
						datelist_item.append(today).append(com);
						datelist_item.click(function(){
							initTaskContent($(this).attr('mid'));
						});
					}

					
				}else{
					new ConsoleItem({
						text:'日期列表加载失败！'+data.pld.mri,
						delay:3000,
						color:'#000000',
						id:'getdatelistfaild'
					});
				}
			}
			
		}).send();
		
		
	}
	
	
	
}
/**
 * 初始化任务内容区域
 * @param mid
 */
function initTaskContent(mid){
	
	var taskconsole = new ConsoleItem({
		text:'正在加载会议记录内容...',
		delay:0,
		id:'loadTaskContent'
	});
	
	
	new Ajax({
		ActionCode:20004,
		prm:{mid:mid},
		Success:function(data){
			taskconsole.fadeClose();
			if(data.res){
				var content = $('.task_div_content');
				content.html('');
				$('.task_div_content_button').remove();
				
				
				var todaydiv = $('<div class="task_div_content_today"></div>').css('background-image','red').css('height','auto').css('width','100%').css('float','left');
				var comdiv = $('<div class="task_div_content_com"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
				var questiondiv = $('<div class="task_div_content_question"></div>').css('background-image','blue').css('height','auto').css('width','100%').css('float','left').css('margin-top','20px');
				
				var todaylabel = $('<div class="label_today"></div>').text('今日计划').css('font-size','20px').css('width','100%').css('float','left');
				var comlabel = $('<div class="label_com"></div>').text('完成情况').css('font-size','20px').css('width','100%').css('float','left');
				var questionlabel = $('<div class="lable_question"></div>').text('遇到问题').css('font-size','20px').css('width','100%').css('float','left');
				
				var todaytext = $('<textarea class="text_today" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.pld.today);
				var comtext = $('<textarea class="text_com" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.pld.com);
				var questiontext = $('<textarea class="text_question" rows="8" cols="80"></textarea>').css('padding','5px').css('width','80%').css('float','left').val(data.pld.question);
				
				
				var buttondiv = $('<div class="task_div_content_button"></div>').css('background-image','blue').css('height','auto').css('top','20%').css('left','88%').css('position','absolute').css('width','80px').css('float','left').css('margin-top','20px');
				
				var button = $('<div class="temp_button">保存修改</div>').attr('mid',mid).css('float','left').css('height','40px').css('line-height','40px').css('width','80px');
				var dateview = $('<div></div>').text($('.datelist_item[mid='+mid+']').attr('dateview')).css('float','left').css('color','blue');
				
				todaydiv.append(todaylabel).append(todaytext);
				comdiv.append(comlabel).append(comtext);
				questiondiv.append(questionlabel).append(questiontext);
				
				buttondiv.append(button).append(dateview);;
				$('body').append(buttondiv);
				content.append(todaydiv).append(comdiv).append(questiondiv);
				
				button.click(function(){
					
					var id = $(this).attr('mid');
					var todaycontent = $('.text_today').val();
					var comcontent = $('.text_com').val();
					var questioncontent = $('.text_question').val();
					
					var savetemp = new ConsoleItem({
						text:'正在保存会议记录...',
						delay:0,
						id:'savetemp'
					});
					
					
					new Ajax({
						ActionCode:20003,
						prm:{
							today:todaycontent,
							com:comcontent,
							question:questioncontent,
							mid:id
						},
						Success:function(data){
							savetemp.fadeClose();
							updateDateList(id, data);
						}
					}).send();
					
				});
			}else{
				
				
				
				
			}
			
			
			
			
			
		}
	}).send();
	
	
	
}
/**
 * 更新日期列表
 * @param mid
 * @param date
 */
function updateDateList(mid,data){
	
	var item = $('.datelist_item[mid='+mid+']');
	var todaycc = data.pld.today;
	var comcc = data.pld.com;
	var questioncc = data.pld.question;
	new ConsoleItem({
		text:'保存会议记录成功!',
		delay:2000,
		color:'#008000',
		id:'savetempsuccess'
	});
	if(item.size() > 0){
		
		var todayspan = item.find('.today_span');
		var comspan = item.find('.com_span');
		
		if(todaycc){
			todayspan.css('color','green');
		}else{
			todayspan.css('color','red');
		}
		if(comcc){
			comspan.css('color','green');
		}else{
			comspan.css('color','red');
		}
		item.find('.q_span').remove();
		
		if(questioncc){
			item.css('padding-left','0');
			var q = $('<span class="q_span">?</span>').css('font-size','20px').css('color','red').css('float','left');
			item.prepend(q);
		}else{
			item.css('padding-left','10px');
		}

	}
	
}

/**
 * 
 */
function loadMoreDate(){
	
	loaddate.index += loaddate.count;
	
	initDateList();
}
/**
 * 重置输入框
 */
function resetInput(){
	$('.login_form_username_input').val('');
	$('.login_form_password_input').val('');
	new ConsoleItem({
		text:'输入框已经重置！',
		delay:3000,
		id:'resetconsole'
	});
}

/**
 * 增加一个控制台元素
 * @param Settings
 */
function ConsoleItem(Settings){
	
	this.text = '';
	this.color = '#000000';
	this.delay = 3000;
	this.status = 0;
	this.id = undefined;
	var pthis = this;
	
	for(var key in Settings){
		this[key] = Settings[key];
	}
	
	var console_content = $('.header_content');
	
	if(this.id != undefined && console_content.find('.console_item[id='+this.id+']').size() > 0){
		return;
	}
	
	var item = $('<div class="console_item"></div>').text(this.text).css('color',this.color).hide().appendTo(console_content);
	
	if(this.id != undefined){
		item.attr('id',this.id);
	}

	
	item.fadeIn(500,function(){
		pthis.status = 1;
		if(pthis.delay != 0){

			setTimeout(function(){
				
				pthis.fadeClose();
				
			},pthis.delay);
		}
		
	});
	
	this.fadeClose = function(){
		item.fadeOut(500,function(){
			pthis.Close();
		});
	}
	this.Close = function(){
		
		pthis.status = 2;
		item.remove();
	}
}

/**
 * ixgsoftAjax工具类
 */
function Ajax(Settings){
	
	this.Servlet = "Main";
	this.ActionCode = " ";
	this.Method = "post";
	this.prm = {};
	this.Success = function(){};
	this.Error = function(){};
	this.Complete = function(){};
	this.dataType = "json";
	this.data = null;
	
	if(Settings){
		for(var key in Settings){
			if(this[key]){
				this[key] = Settings[key];
			}
		}
	}
	this.RequestJson = {
		cod: this.ActionCode,
		prm: this.prm
	};
	var p_this = this;
	
	this.send = function(run){
		if(run != undefined){
			run();
		}
		if(this.Method == "post"){
			$.post(this.Servlet,{
				json:JSON.stringify(this.RequestJson)
			},function(data){
				this.data = data;

				p_this.Success(data);
				
			},this.dataType).error(this.Error).complete(this.Complete);
		}
		if(this.Method == "get"){
			$.get(this.Servlet,{
				json:JSON.stringify(this.RequestJson)
			},function(data){
				this.data = data;

				p_this.Success(data);

			},this.dataType).error(this.Error).complete(this.Complete);
		}
	};
	this.set = function(key,value){
		if(this[key]){
			this[key] = value;
		}
	};
	
	
}
/**
 * 弹出层
 * @param Settings
 */
function Dialog(Settings){
	
	this.width = 400;
	this.height = 300;
	this.content = '';
	
	for(var key in Settings){
		this[key] = Settings[key];
	}
	
	this.bg = $('<div class="temo_dialog_bg"></div>').css('height','100%').css('width','100%').css('z-index','10001').css('position','absolute').css('background-color','black').css('opacity','0.5');
	this.div = $('<div class="temo_dialog_div"></div>').css('padding','5px').html(this.content).css('top','50%').css('left','50%').css('margin-left','-'+this.width/2+'px').css('margin-top','-'+this.height/2+'px').css('border','3px solid #000000').css('z-index','10002').css('position','absolute').css('background-color','white').css('width',this.width).css('height',this.height);
	
	this.show = function(){
		$('body').append(this.bg);
		$('body').append(this.div);
	};
	
	this.close = function(){
		this.bg.remove();
		this.div.remove();
	};
	
}
